<?php
/*
 * @version :  2013-2-10
 * @project :  account-system
 * @Author  :  Allen
 * @e-mail  :  shulei@maszy.cn
 */
require_once (dirname(__FILE__)."/../config/config.php");
//activeA2BUser('16800100','18475361','束磊','13855585327','shulei@qq.com','114.114.114.114');
if(isset($_POST)){
	if($_POST['method']=='activeA2BUser'){
		$usernamae=$_POST['username'];
		$password=$_POST['password'];
		$realname=$_POST['realname'];
		$phone=$_POST['phone'];
		$email=$_POST['email'];
		$ip=$_POST['ip'];
		$result=activeA2BUser($usernamae,$password,$realname,$phone,$email,$ip);
		echo json_encode($result);
	}
}
/**
 * 激活中间平台帐号.
 */
function activeA2BUser($username,$password,$realname,$phone,$email,$ip){
	$sql="select * from zy_user where user_name='$username' and password='$password'";
	$user_result = mysql_query($sql);
	$user = mysql_fetch_array($user_result);
	if($user=='')
		return '001';//错误代码001,帐号密码输入错误;
	if($user['isdelete']==0)
		return '002';//错误代码002,帐号已激活;
	if($user['isdelete']==2)
		return '003';//错误代码003,帐号未开通电话服务;
	if($user['isdelete']==1){
		$user_update_sql="update zy_user set isdelete=0 where user_id=".$user['user_id'];
		mysql_query($user_update_sql);
		//发送邮件
		sendEmail($username,$password,$realname,$phone,$email,$ip);
		return 1;
	}else{
		return '004';//错误代码004,未知错误.联系管理员;
	}
}
function sendEmail($username,$password,$realname,$phone,$email,$ip){
	$msg = "账号:\t$username\n"; 
	$msg .= "密码:\t$password\n";
	$msg .= "姓名:\t$realname\n";
	$msg .= "电话:\t$phone\n";
	$msg .= "邮箱:\t$email\n";
	$msg .= "IP:\t$ip\n";
	$recipient = "zy.shulei@gmail.com,marshall.ma@webnova.net.au,aaron.zhao@webnova.net.au"; 
	//$recipient = "allen6203@qq.com"; 
	$subject = "澳洲行活动帐号激活";
	$mailheaders = "From: $realname <$email> \n"; 
	$mailheaders .= "Reply-To: $sender_email\n\n";
	mail($recipient, $subject, $msg, $mailheaders);	
}

?>
